{extend name="common/layout" /}
{block name="main"}
<div class="admin-main layui-anim layui-anim-upbit">

    <div class="padding30">
       <h3 class="page-box-title">{:lang('Line Configuration')}</h3>

    <div class="demoTable">
        <form class="layui-form ">
        <div class="layui-inline layui-search">
            <select name="type" class="layui-search-select" id="_type">
                <option value="">{:lang('Choose A Type')}</option>
                <?php foreach($typeList as $type=>$typeLabel):?>
                <option value="{$type}" <?php if($row['area_id'] == $type){echo "selected"; }?>>{$typeLabel}</option>
                <?php endforeach;?>
          </select>
          </div>
          <div class="layui-inline">
            <div class="layui-form-item" style="margin-bottom:0">
                <div class="layui-input-inline" style="width: 150px;">
                  <input type="text" name="min_mbps" id="_min_mbps" style="border-radius: 10px;" value="{$row['min_mbps']}" placeholder="{:lang('field_min_mbps')}" autocomplete="off" class="layui-input layui-search-input">
                </div>
                <div class="layui-form-mid" style="color: #fff;">-</div>
                <div class="layui-input-inline" style="width: 150px;">
                  <input type="text" name="max_mbps"  id="_max_mbps" value="{$row['max_mbps']}" placeholder="{:lang('field_max_mbps')}" autocomplete="off" class="layui-input layui-search-input">
                </div>
            </div>
          </div>
         <button class="layui-btn layui-search-btn borderrad5" type="button" id="search" data-type="reload" style="margin-left: -23px;">{:lang('Search')}</button>
            <button type="button" data-title="{:lang('import')}" data-btn="{:lang('Next Step')}" class="layui-btn layui-btn-warm borderrad5" data-model="prices" data-url="{:U('UpFiles/import',['model'=>'prices'])}" id="_upload">{:lang('import')}</button>
            <button class="layui-btn layui-btn-primary showtypemodel borderrad5" type="button" data-title="{:lang('Update Cost')}" data-url="{:U('reloadPrice')}" id="reload-price">{:lang('Update Cost')}</button>
        
        <div style="clear: both;"></div>
         </form>
    </div>
        
    </div>
    <div class="" id="_listBox">
        <div style="text-align: right;"><a href="{:url('add')}" class="layui-btn layui-btn-normal layui-btn-add borderrad5 " title="{:lang('Add')}" ><i class="icon icon-plus"></i></a></div>

        <table class="layui-table" id="list" lay-filter="list"></table>
    </div>
</div>
{/block}
{block name="footer"}
<script type="text/html" id="order">
    <input name="{{d.id}}" data-id="{{d.id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
</script>
<script type="text/html" id="order">
    
</script>
<script type="text/html" id="name">
    {{# if(d.name != '' && d.name != null){ }}
      {{d.name}}
    {{# }else{ }}
        --
    {{# } }}
</script>

<script type="text/html" id="action">
    <a data-href="" href="{:url('edit')}?id={{d.id}}" class=" ">{:lang('Edit')}</a> | 
    <a class="" lay-event="delete">{:lang('Delete')}</a>
</script>
<script type="text/javascript" id="reload-from">
    
    <div style="padding: 15px 10px;">
    <blockquote class="layui-elem-quote">
        {:lang('Note: Please select the updated interface type and update it slowly. Please wait patiently.')}
    </blockquote>
        <fieldset class="layui-elem-field" style="padding: 15px 10px;">
          <legend>{:lang('Interface Type')}</legend>
          <form class="" action="{:U('import')}" id="form-import">
          <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left:30px;">
            <?php foreach($pricemodel as $ml=>$m):?>
              <label><input type="radio" class="modeltypes" name="modeltypes" value="{$ml}" title="{$m}" style="position: relative;top: 2px;"> {$m['lebal']}</label> 
              <?php endforeach;?>
            </div>
          </div>
          </form>
        </fieldset>
    </div>
</script>
<script type="text/javascript">
	layui.use('table', function() {
		 var table = layui.table, $ = layui.jquery,form = layui.form;
		 var tableIn = table.render({
        elem: '#list'
        ,url: '{:url("index")}',
        method:'post',
        page:getPageThume()
        ,cols: [[
            // {checkbox: true, fixed: true},
            {field:'typelabel', title: "{:lang('Type')}", width:"13%",sort:true},
            {field:'country', title: "{:lang('Z-END Country')}", width:"10%",sort:true},
            {field:'name', title: "{:lang('Z-END City')}", width:"10%",sort:true,templet: '#name'},
            {field: 'mbps', align: 'center', title: '{:lang("broadband")}', width:"12%",sort:true},
            {field: 'rmb1', align: 'center', title: '{:lang("Monthly")}', width:"12%",sort:true},
            {field: 'usd1', align: 'center', title: '{:lang("Monthly")}', width:"12%",sort:true},
            {field: 'rmb3', align: 'center', title: '{:lang("Quarter")}', width:"12%",sort:true},
            {field: 'usd3', align: 'center', title: '{:lang("Quarter")}', width:"12%",sort:true},
            {field: 'rmb6', align: 'center', title: '{:lang("Semiannual")}', width:"12%",sort:true},
            {field: 'usd6', align: 'center', title: '{:lang("Semiannual")}', width:"12%",sort:true},
            {field: 'rmb12', align: 'center', title: '{:lang("Year")}', width:"12%",sort:true},
            {field: 'usd12', align: 'center', title: '{:lang("Year")}', width:"12%",sort:true}
            ,{width:"8%",title: "{:lang('Operating')}", align:'right', toolbar: '#action'}
        ]]
    });
     form.on('switch(status)', function(obj){
        loading =layer.load(1, {shade: [0.1,'#fff']});
        var id = this.value;
        var status = obj.elem.checked===true?1:0;
        $.post('{:url("editState")}',{'id':id,'status':status},function (res) {
            layer.close(loading);
            if (res.status==1) {
                tableIn.reload();
            }else{
                layer.msg(res.msg,{time:1000,icon:2});
                return false;
            }
        })
    });
      table.on('tool(list)', function(obj) {
        var data = obj.data;
        if (obj.event === 'delete'){
            layer.confirm('{:lang("Are you sure you want to delete the record?")}', function(index){
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('delete')}",{id:data.id},function(res){
                    layer.close(loading);
                    if(res.code===1){
                        obj.del();
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
                layer.close(index);
            });
        }
    });
      //搜索
    $('#search').on('click', function () {
        var type = $('#_type').val();
        var min_mbps = $("#_min_mbps").val();
        var max_mbps = $("#_max_mbps").val();
        tableIn.reload({
            where: {type: type,min_mbps:min_mbps,max_mbps:max_mbps}
        });
    });

     $('body').on('blur','.list_order',function() {
        var id = $(this).attr('data-id');
        var sort = $(this).val();
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.post('{:url("sort")}',{id:id,sort:sort},function(res){
            layer.close(loading);
            if(res.code === 1){
                layer.msg(res.msg, {time: 1000, icon: 1});
            }else{
                layer.msg(res.msg,{time:1000,icon:2});
            }
        })
    });
     $('body').on("click",'._showmodel',function(){
          var url = $(this).data('href');
          layer.open({
            type: 2, //此处以iframe举例
            title: "{:lang('New Configuration')}",
            area: ['700px', '640px'],
            shade: 0.7,
            maxmin: true,
            content:url
         })
       })
      $("body").on("click",".showtypemodel",function(){
        var _this = $(this);
        var ids = [];
          var model = layer.open({
            type: 1, //此处以iframe举例
            title: _this.data('title'),
            area: ['500px', '350px'],
            shade: 0.7,
            btn: ["{:lang('Submit')}"], //只是为了演示
            maxmin: true,
            content:$("#reload-from").html(),
            btn1:function(index, layero){
                if(undefined == $(".modeltypes:checked").val() || $(".modeltypes:checked").val() == ''){
                    layer.msg("{:lang('Please select interface type.')}",{time:1000,icon:2});
                    return false;
                }
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post(_this.data('url'),{ids:ids,modeltypes:$(".modeltypes:checked").val()},function(res){
                    layer.close(loading);
                    if(res.code == 1){
                        if(res.url != undefined && res.url != '' && res.url != null){
                            location.href = res.url;
                        }
                        layer.msg(res.msg,{time:1000,icon:1},function(){
                            layer.close(model);
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                })
            }
         })
      })
	})
</script>
{/block}